package codeGeneration.bean;

import java.util.ArrayList;
import java.util.List;

import util.FileUtil;

import databaseTransaction.Table;
import databaseTransaction.TableField;

public class JDBCClassGenerator extends ClassGenerator {
	public JDBCClassGenerator(Table table, String basePath, String packageName) {
		super(table, table.getName());
		this.packageName = packageName;
		this.fileLocation = basePath + '/' + packageName.replace('.', '/');

		FileUtil.mkDir(fileLocation);
	}

	public void generateDeclare() {
		headerOfJavaFile.setPackageName(packageName);
		indentOneTime("public class " + this.table.getName(), null, " {",
				sbuffWriter, false);

		List<TableField> allField = new ArrayList<TableField>(
				this.table.getId()); // combine all fields include PK and non PK
		allField.addAll(this.table.getTableFields());

		for (TableField tblField : allField)
			appendToFile(sbuffWriter,
					"private " + tblField.parseType() + " "
							+ tblField.getName() + ";\n");

	}
}
